﻿// SKNotes - a note taking and gathering tool
// Copyright (C) 2009  Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Media;
using System.Windows.Input;

namespace SKNotes.CustomControls.TaskDialog
{
    /// <summary>
    /// Interaction logic for TaskDialogWindow.xaml
    /// </summary>
    public partial class TaskDialogWindow : InteropWindow
    {
        internal TaskDialogWindow()
        {
            InitializeComponent();
        }

        protected override void OnShowWindow()
        {
            // Plays a system sound when the window is initialized (shown)
            TaskDialog td = Content as TaskDialog;
            if (td != null)
            {
                td.OnWindowInitialized();       // raises the WindowInitialized event
                switch (td.SystemSound)
                {
                    case TaskDialogSound.Beep:
                        SystemSounds.Beep.Play();
                        break;

                    case TaskDialogSound.Exclamation:
                        SystemSounds.Exclamation.Play();
                        break;

                    case TaskDialogSound.Hand:
                        SystemSounds.Hand.Play();
                        break;

                    case TaskDialogSound.Question:
                        SystemSounds.Question.Play();
                        break;

                    case TaskDialogSound.Asterisk:
                        SystemSounds.Asterisk.Play();
                        break;
                }
            }
        }
        protected override void OnClosed(EventArgs e)
        {
            TaskDialog td = Content as TaskDialog;
            if (td != null)
                td.OnClosing();

            this.Content = null;
            base.OnClosed(e);
        }

        protected override void OnKeyUp(System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                TaskDialog td = Content as TaskDialog;
                if (td != null)
                    td.OnEscape();
            }
        }
    }
}
